<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">负责人</label>
        <!-- <el-input v-model="query.administrator" clearable placeholder="负责人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <el-select
          v-model="query.administrator"
          placeholder="请选择负责人"
          style="width: 185px"
          clearable
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        >
          <el-option
            v-for="item in allUsers"
            :key="item.id"
            :label="item.username"
            :value="item.id"
          />
        </el-select>
        <label class="el-form-item-label">实验室</label>
        <el-select
          v-model="query.labId"
          placeholder="请选择实验室"
          style="width: 185px"
          clearable
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        >
          <el-option
            v-for="item in allLabs"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <!-- <el-input v-model="query.labId" clearable placeholder="实验室" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <!-- <label class="el-form-item-label">名称</label> -->
        <!-- <el-input v-model="query.name" clearable placeholder="名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          size="small"
          label-width="80px"
        />
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button
            :loading="crud.status.cu === 2"
            type="primary"
            @click="crud.submitCU"
            >确认</el-button
          >
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%"
        @selection-change="crud.selectionChangeHandler"
      >
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="name" label="名称"  align="center"/>
        <el-table-column prop="labName" label="实验室"  align="center"/>
        <el-table-column prop="administratorName" label="负责人"  align="center"/>
        <el-table-column prop="temperature" label="温度" align="center">
          <template slot-scope="scope">
            {{ scope.row.temperature }}°C
          </template>
        </el-table-column>
        <el-table-column prop="temperatureThresholdValue" label="温度阈值" align="center">
          <template slot-scope="scope">
            {{ scope.row.temperatureThresholdValue }}°C
          </template>
        </el-table-column>
        <el-table-column prop="errorMessage" label="报警信息"  align="center"/>
        <!-- <el-table-column v-if="checkPer(['admin','incubatorLog:edit','incubatorLog:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudIncubatorLog, { searchId } from "@/api/incubatorLog";
import CRUD, { presenter, header, form, crud } from "@crud/crud";
import rrOperation from "@crud/RR.operation";
import crudOperation from "@crud/CRUD.operation";
import udOperation from "@crud/UD.operation";
import pagination from "@crud/Pagination";
import { mapState } from "vuex";

const defaultForm = {
  isDeleted: null,
  updatedAt: null,
  createdAt: null,
  errorMessage: null,
  temperatureThresholdValue: null,
  temperature: null,
  administrator: null,
  labId: null,
  incubatorId: null,
  name: null,
  id: null,
};
export default {
  name: "IncubatorLog",
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: "培养箱日志",
      url: "api/incubatorLog",
      idField: "id",
      sort: "id,desc",
      crudMethod: { ...crudIncubatorLog },
    });
  },
  data() {
    return {
      permission: {
        add: ["admin", "incubatorLog:add"],
        edit: ["admin", "incubatorLog:edit"],
        del: ["admin", "incubatorLog:del"],
      },
      rules: {},
      queryTypeOptions: [
        { key: "administrator", display_name: "负责人" },
        { key: "labId", display_name: "实验室" },
        { key: "name", display_name: "名称" },
      ],
    };
  },
  computed: {
    ...mapState("hjuser", ["systemSearchInfoId", "allLabs", "allUsers"]),
  },
  created() {
    this.crud.optShow = {
      add: false,
      del: false,
      download: true,
      edit: false,
      reset: true
    };
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    },
    async [CRUD.HOOK.afterRefresh]() {
      if (this.systemSearchInfoId) {
        const res = await searchId(this.systemSearchInfoId);
        this.crud.data = res.content;
        this.$store.commit("hjuser/updatedsystemSearchInfoId", "");
      }
      return true;
    },
  },
};
</script>

<style scoped>
</style>
